//
//  AppDelegate.swift
//  sina
//
//  Created by Kent on 16/9/22.
//  Copyright © 2016年 Ming. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        registerNotification()
        self.window = UIWindow(frame:UIScreen.main.bounds)
        self.window?.backgroundColor = UIColor.white
        
        self.window?.rootViewController = HMUserAccountViewModel.sharedAccountViewModel.userLogin ? HMWelcomeViewController() : HMTabBarController()
        self.window?.makeKeyAndVisible()
        
        return true
    }

    func registerNotification() {
        
        NotificationCenter.default.addObserver(self, selector: #selector(setRootViewController(n:)), name: NSNotification.Name(rawValue: KchangeRootViewController), object: nil)
        
    }
    
    @objc private func setRootViewController(n: Notification) {
        if n.object != nil {
            window?.rootViewController = HMWelcomeViewController()
        } else {
            window?.rootViewController = HMTabBarController()
        }
    }

    deinit {
        NotificationCenter.default.removeObserver(self)
    }
}

